package cn.wolfcode.controller;

import cn.wolfcode.domian.Result;
import cn.wolfcode.domian.dept;
import cn.wolfcode.service.deptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/depts")
public class deptController {
    @Autowired
    private deptService deptService;
    @GetMapping
    public Result list(){
        log.info("查询所有部门");
   List<dept> depts = deptService.list();
        return Result.success(depts);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
        log.info("删除部门");
        deptService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody dept dept){
        log.info("添加部门");
         deptService.add(dept);
         return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        log.info("查询部门");
        dept dept = deptService.getById(id);
        return Result.success(dept);
    }

    @PutMapping
    public Result update(@RequestBody dept dept){
        log.info("修改部门");
         deptService.update(dept);
         return Result.success();
    }
}
